﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Sys.Interfaces;
using AMS.DataAccess.Sys.BO;

public partial class Security_AddUsersToRoleDlg : BaseWorkPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Utils.ParseIntQueryString(Request, "id", ref roleId))
        {
            GlobalTransfer.RedirectToErrorPage("参数错误");
            return;
        }

        if (!IsPostBack)
        {
            DoDataBind();
        }
    }

    int roleId;
    void DoDataBind()
    {
        IUserManager userMgr = ManagerFactory.CreateUserManager();
        List<UserInfo> users = userMgr.GetUsersExcludedOfRole(CallContext, roleId);
        gv.DataSource = users;
        gv.DataKeyNames = new string[] { "AID" };
        gv.DataBind();
    }
    protected string FormatDateTime(object value, bool showTime)
    {
        return Utils.FormateDateTime(value, showTime);
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        List<int> selectedUserIDs = Utils.GetGridViewCheckItemIDs(gv);
        if (selectedUserIDs.Count == 0)
        {
            lblMsg.Text = "没有选择";
            return;
        }

        IRoleManager roleMgr = ManagerFactory.CreateRoleManager();
        int count = roleMgr.BatchAddRoleUsers(CallContext, roleId, selectedUserIDs);
        lblMsg.Text = "成功：" + count.ToString();
        hfItems.Value = count.ToString();
        DoDataBind();
    }
}
